package com.sq.partner.manager.util;

import org.jasypt.util.text.BasicTextEncryptor;

public class EncryptionUtil {

    private static String PASSWORD = "CIC_PARTNER_*#";

    /**
     * 加密
     * 可解密
     * @param password
     * @return
     */
    public static String getEncryptionPassword(String key, String password) {
        if (null == key || "".equals(key)) {
            key = PASSWORD;
        }
        if (null == password || "".equals(password)) {
            return password;
        }
        BasicTextEncryptor textEncryptor = new BasicTextEncryptor();
        textEncryptor.setPassword(key);
        String encryptionStr = textEncryptor.encrypt(password);
        return encryptionStr;
    }

    /**
     * 解密
     * 
     * @param encryptionPassword
     * @return
     */
    public static String getUnEncryptionPassword(String key, String encryptionPassword) {
        if (null == key || "".equals(key)) {
            key = PASSWORD;
        }
        if (null == encryptionPassword || "".equals(encryptionPassword)) {
            return encryptionPassword;
        }
        BasicTextEncryptor textEncryptor2 = new BasicTextEncryptor();
        textEncryptor2.setPassword(key);
        String unEncryptionPassword = textEncryptor2.decrypt(encryptionPassword);
        return unEncryptionPassword;
    }

    public static void main(String[] args) {
        EncryptionUtil eu = new EncryptionUtil();
        String str = eu.getEncryptionPassword(PASSWORD, "吉祥1");
//        System.out.println(str);
        System.out.println("code: " + eu.getUnEncryptionPassword(PASSWORD, "lJTRwK1hdRWgjP+dUyKXBQ=="));
    }
}
